# install.packages("devtools")
# devtools::install_github("MathiasHarrer/dmetar")

library(dmetar)
library("meta")

# 
# GLPT1DMMETA= read.rm5(
#   "GLP-1 for Type 1 Diabetes- Raw Final.rm5",
#   sep = ",",
#   quote = "\"",
#   "GLP-1 for Type 1 Diabetes- Raw Final",
#   numbers.in.labels = TRUE,
#   debug = 0
# )
# 
# c1o3<- metacr(GLPT1DMMETA,comp.no=1, outcome.no=3)
# funnel(c1o3)
# 
# # Contour-enhanced funnel plot with user-chosen colours
# #
# funnel(c1o1, random = TRUE,
#        level = 0.95,  contour = c(0.9, 0.95, 0.99),
#        col.contour = c("darkgreen", "green", "lightgreen"),  
#        lwd.random = 2, cex=1,
#        studlab = TRUE, pos.studlab=1, cex.studlab = 0.7)
# legend(0.05, 0.05,
#        c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
#        fill = c("darkgreen", "green", "lightgreen"))
#        





GLPT1DMMETA_p= read.rm5(
  "GLP-1 for Type 1 Diabetes- pubbias2.rm5",
  sep = ",",
  quote = "\"",
  "GLP-1 for Type 1 Diabetes- pubbias2",
  numbers.in.labels = TRUE,
  debug = 0
)

c1o1 <- metacr(GLPT1DMMETA_p,comp.no=1, outcome.no=1)
funnel(c1o1, random = TRUE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(0.95, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))
metabias(c1o1, method.bias = "mm")
# eggers.test(c1o1)

c1o2 <- metacr(GLPT1DMMETA_p,comp.no=1, outcome.no=2)
funnel(c1o2, random = TRUE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(-9.5, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))
metabias(c1o2, method.bias = "mm")
# eggers.test(c1o2)


c1o3 <- metacr(GLPT1DMMETA_p,comp.no=1, outcome.no=3)
funnel(c1o3, random = TRUE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(7, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))
metabias(c1o3, method.bias = "mm")
# eggers.test(c1o3)



c1o4 <- metacr(GLPT1DMMETA_p,comp.no=1, outcome.no=4)
funnel(c1o4, random = TRUE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(0.1, 0.005,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))
metabias(c1o4, method.bias = "mm")
# eggers.test(c1o4)



GLPT1DMMETA= read.rm5(
  "GLP-1 for Type 1 Diabetes- pubbias adverse.rm5",
  sep = ",",
  quote = "\"",
  "GLP-1 for Type 1 Diabetes- pubbias adverse",
  numbers.in.labels = TRUE,
  debug = 0
)


c1o5 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=5)
funnel(c1o5, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(7, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))



c1o6 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=6)
funnel(c1o6, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(7, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))


c1o7 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=7)
funnel(c1o7, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(25, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))


c1o8 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=8)
funnel(c1o8, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(30, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))

c1o9 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=9)
funnel(c1o9, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(30, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))


c1o10 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=10)
funnel(c1o10, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(10, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))


c1o11 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=11)
funnel(c1o11, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(30, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))



c1o12 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=12)
funnel(c1o12, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(10, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))



c1o13 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=13)
funnel(c1o13, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(3, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))




c1o14 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=14)
funnel(c1o14, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(7, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))



c1o15 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=15)
funnel(c1o15, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(7, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))



c1o16 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=16)
funnel(c1o16, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(5, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))


c1o17 <- metacr(GLPT1DMMETA,comp.no=1, outcome.no=17)
funnel(c1o17, random = FALSE,
       level = 0.95,  contour = c(0.9, 0.95, 0.99),
       col.contour = c("darkgreen", "green", "lightgreen"))
legend(10, 0.05,
       c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
       fill = c("darkgreen", "green", "lightgreen"))


metabias(c1o5, method.bias = "Harbord")
metabias(c1o6, method.bias = "Harbord")
metabias(c1o7, method.bias = "Harbord")
metabias(c1o8, method.bias = "Harbord")
metabias(c1o9, method.bias = "Harbord")
metabias(c1o10, method.bias = "Harbord")
metabias(c1o11, method.bias = "Harbord")
metabias(c1o12, method.bias = "Harbord")
metabias(c1o13, method.bias = "Harbord")
metabias(c1o14, method.bias = "Harbord")
metabias(c1o15, method.bias = "Harbord")
metabias(c1o16, method.bias = "Harbord")
metabias(c1o17, method.bias = "Harbord")


# 
# 
# 
# c2o1 <- metacr(GLPT1DMMETA_p,comp.no=2, outcome.no=1)
# funnel(c2o1, random = TRUE,
#        level = 0.95,  contour = c(0.9, 0.95, 0.99),
#        col.contour = c("darkgreen", "green", "lightgreen"),
#        lwd.random = 2, cex=1,
#        studlab = TRUE, pos.studlab=2, cex.studlab = 0.7)
# legend(0.95, 0.05,
#        c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
#        fill = c("darkgreen", "green", "lightgreen"))
# eggers.test(c2o1)
# 
# c2o2 <- metacr(GLPT1DMMETA_p,comp.no=2, outcome.no=2)
# funnel(c2o2, random = TRUE,
#        level = 0.95,  contour = c(0.9, 0.95, 0.99),
#        col.contour = c("darkgreen", "green", "lightgreen"),
#        lwd.random = 2, cex=1,
#        studlab = TRUE, pos.studlab=2, cex.studlab = 0.7)
# legend(-1.5, 0.05,
#        c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
#        fill = c("darkgreen", "green", "lightgreen"))
# eggers.test(c2o2)
# 
# 
# c2o3 <- metacr(GLPT1DMMETA_p,comp.no=2, outcome.no=3)
# funnel(c2o3, random = TRUE,
#        level = 0.95,  contour = c(0.9, 0.95, 0.99),
#        col.contour = c("darkgreen", "green", "lightgreen"),
#        lwd.random = 2, cex=1,
#        studlab = TRUE, pos.studlab=2, cex.studlab = 0.7)
# legend(7, 0.05,
#        c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
#        fill = c("darkgreen", "green", "lightgreen"))
# eggers.test(c2o3)
# 
# 
# 
# c2o4 <- metacr(GLPT1DMMETA_p,comp.no=2, outcome.no=4)
# funnel(c2o4, random = TRUE,
#        level = 0.95,  contour = c(0.9, 0.95, 0.99),
#        col.contour = c("darkgreen", "green", "lightgreen"),
#        lwd.random = 2, cex=1,
#        studlab = TRUE, pos.studlab=2, cex.studlab = 0.7)
# legend(0.1, 0.005,
#        c("0.1 > p > 0.05", "0.05 > p > 0.01", "< 0.01"),
#        fill = c("darkgreen", "green", "lightgreen"))
# eggers.test(c2o4)
# 
# 
